package com.edu.test.idTest;

import cn.hutool.core.util.IdUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

/**
 * @作者 five-five
 * @创建时间 2021/1/11
 */
public class IDUtilClient {
    public static void main(String[] args) throws Exception {
        IDUtilClient idUtilClient = new IDUtilClient();
        List<String> test01 = idUtilClient.test01();
        List<String> test02 = idUtilClient.test02();
        test01.stream().forEach(string->{
            System.out.print(string+"\t");
        });
        System.out.println();
        test02.stream().forEach(string->{
            System.out.print(string+"\t");
        });
    }

    /**
     * 测试IDutil
     * @return
     */
    public List<String> test01(){
        List<String> list = new ArrayList<>();
        for (int i = 100; i > 0; i--) {
            Thread thread = new Thread(() -> {
                String dateSimpleUUID = IDUtil.getDateSimpleUUID();
                list.add(dateSimpleUUID);
            });
            thread.run();
        }
        return list;
    }

    /**
     * 测试hutool的IdUtil
     * @return
     */
    public List<String> test02(){
        List<String> list = new ArrayList<>();
            ExecutorService executorService = Executors.newFixedThreadPool(10);
            executorService.execute(() -> {
                String dateSimpleUUID = IdUtil.getSnowflake(1l,1l).nextIdStr();
                list.add(dateSimpleUUID);
            });
        if (!(list.size() <10)) {
            executorService.shutdown();
        }
        return list;
    }
}
